
void setup (){
  pinMode(9,OUTPUT);//D0
  pinMode(10,OUTPUT);//D3
  pinMode(A1,OUTPUT);//ACK
  pinMode(11,OUTPUT);//D2
  pinMode(12,OUTPUT);//D1
  pinMode(A0,INPUT);//rACK
  digitalWrite(A1,HIGH);
  digitalWrite(10,LOW);
  digitalWrite(9,0);
  Serial.begin(115200);
}

void loop(){
 char x;
  if(Serial.available()){
  x = Serial.read();
  Serial.println(x,HEX);
  tulis(x);
 } 
  
}

void tulis(char ch){
  digitalWrite(10,(ch & 128));//D3
  digitalWrite(11,(ch & 64));//D2
  digitalWrite(12,(ch & 32));//D1
  digitalWrite(9, (ch & 16));//D0
  digitalWrite(A1,LOW);
  while(digitalRead(A0) == HIGH){}
  digitalWrite(A1,HIGH);
  while(digitalRead(A0) == LOW){}
  digitalWrite(10,(ch & 8));//D3
  digitalWrite(11,(ch & 4));//D2
  digitalWrite(12,(ch & 2));//D1
  digitalWrite(9, (ch & 1));//D0
  digitalWrite(A1,LOW);
  while(digitalRead(A0) == HIGH){}
  digitalWrite(A1,HIGH);
  while(digitalRead(A0) == LOW){}
}
